package com.jiaai.cloud.chatroom.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.jiaai.cloud.base.exception.ServiceException;
import com.jiaai.cloud.base.page.FrontPage;
import com.jiaai.cloud.base.util.RestResultGenerator;
import com.jiaai.cloud.chatroom.entity.TChatRoomMember;
import com.jiaai.cloud.chatroom.service.ITChatRoomMemberService;
import com.jiaai.cloud.gift.entity.TLiveGift;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 * 聊天室成员表 前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2017-08-01
 */
@Controller
@RequestMapping("/api/manage/tChatRoomMember")
public class TChatRoomMemberController {
	@Autowired
	private ITChatRoomMemberService itChatRoomMemberService;
    //查所有
    @RequestMapping(value ="/findByAll",method = RequestMethod.GET,produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object findByAll(FrontPage page) throws ServiceException {
        try {
            EntityWrapper wrapper=new EntityWrapper();
            return RestResultGenerator.genSuccessResult(itChatRoomMemberService.findCharFully(page.getPagePlus(),wrapper));
        } catch (Exception e) {
            throw new ServiceException("查询失败", e.getMessage());
        }
    }

    //通过改anchorId改status状态
    @RequestMapping(value = "/changeStatus/{id}/{status}", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"})
    @ResponseBody
    public Object changeStatus( @PathVariable("id") Integer id, @PathVariable("status") Integer status ) throws ServiceException {
        try {
            TChatRoomMember tChatRoomMember = new TChatRoomMember();
            tChatRoomMember.setId(id);
            tChatRoomMember.setStatus(status);
            itChatRoomMemberService.updateById(tChatRoomMember);
            return RestResultGenerator.genSuccessResult("");
        }catch (Exception e) {
            throw new ServiceException("修改失敗", e.getMessage());
        }
    }

    //    删除
    @RequestMapping(value = "/deleteId/{id}", method = RequestMethod.GET, produces = {"application/json;charset=UTF-8"})
    public Object deleteId(@PathVariable("id") Integer id) throws ServiceException {
        try {
            itChatRoomMemberService.deleteById(id);
            return RestResultGenerator.genSuccessResult();
        } catch (Exception e) {
            throw new ServiceException("删除失敗", e.getMessage());
        }
    }

}
